The example below shows how to get a pre-configured repository by name, and to list the resources it contains.
In [1]:
from bdkd import datastore as ds
# This repository is pre-configured
repo = ds.repositories().get('bdkd-laser-public')
# List all resources in the repository
repo.list()
Out[1]:
Resources can be acquired from the repository by name.
The metadata for a resource is available via .metadata. This includes any metadata that was set when the resource was created, as key/value pairs.
In [2]:
dataset = repo.get('datasets/Sample dataset')
dataset.metadata
Out[2]:
A resource consists of one or more files. In this example (an experiment) there are many files, including raw data, maps and a README.
In [3]:
len(dataset.files)
Out[3]:
We can narrow down the list of files. In this case, we will narrow down by name: we know the files that contain "FB_" in their name are the raw data files.
In [4]:
raw_files = dataset.files_matching('FB_')
len(raw_files)
Out[4]:
So far we've been manipulating the files in abstract: none of the actual file data has been retrieved from the repository.
This is where magic happens...
The method .local_path() is special: it fetches and caches the file in the local filesystem, returning a path via which the file can be opened. Let's do that for the first raw file for example.
In [6]:
path_to_file = raw_files[0].local_path()
print path_to_file
We can then open the file and work with it. Example:
In [7]:
import h5py
h5f = h5py.File(path_to_file)
for ds in h5f:
inj = h5f[ds].attrs['INJ']
fb = h5f[ds].attrs['FB']
print "Feedback: " + str(fb) + " injection: " + str(inj)
h5f.close()
The dataset should contain a file called "maps.hdf5" that contains all the feedback/injection maps calculated for the dataset.
We cache/aquire this file, open it, then list its contents.
In [3]:
import h5py
maps = h5py.File(dataset.file_ending('maps.hdf5').local_path())
maps.items()
Out[3]:
We are interested in the feedback and injection maps. They are used for plotting.
We will also get a set of permutation entropy calculations -- in this case "PE_map_m5t01.csv".
In [4]:
FBT = maps['FBT_map.csv'][()]
INJ = maps['INJ_map.csv'][()]
pes = maps['PE_map_m5t01.csv'][()]
In [5]:
plt
Out[5]:
In [7]:
%matplotlib inline
import numpy as np
mapX = np.array(INJ)
mapY = np.array(FBT)
mapZ = np.array(pes)
fig = plt.figure(figsize=(4.07, 4.40), dpi=100)
plt.pcolor(mapX, mapY, mapZ)
plt.axes().set_xlim(np.min(mapX), np.max(mapX))
plt.axes().set_ylim(np.min(mapY), np.max(mapY))
plt.colorbar()
Out[7]: